<?php
/**
* @file $Id: Letters.php 161 2006-09-07 06:21:17Z doritojones $
* @package Focus/SIS
* @copyright Copyright (C) 2006 Andrew Schmadeke. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.txt
* Focus/SIS is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.txt for copyright notices and details.
*/

$extra['action'] .= "&_FOCUS_PDF=true";
Widgets('document_template');
Widgets('mailing_labels');
/*Widgets('course');
Widgets('request');
Widgets('activity');
Widgets('absences');
Widgets('gpa');
Widgets('class_rank');
Widgets('letter_grade');
Widgets('eligibility');*/
Widgets('all');
$extra['force_search'] = true;

$extra['second_col'] = '<fieldset><legend>'._('Letter Text').'</legend><TEXTAREA name=letter_text rows=20 cols=45></TEXTAREA></fieldset>'.$extra['second_col'];
if(!$_REQUEST['search_modfunc'] || $_FOCUS['modules_search'])
{
	DrawHeader(ProgramTitle());

	$extra['new'] = true;
	Search('student_id',$extra);
}
else
{
	$RET = GetStuList($extra);
	
	if(count($RET))
	{
		$_REQUEST['letter_text'] = nl2br(str_replace("\'","'",str_replace('  ',' &nbsp;',$_REQUEST['letter_text'])));

		$handle = PDFStart();
		foreach($RET as $student)
		{
			$student_id = $student['STUDENT_ID'];
			$student_points = $total_points = 0;
			unset($_FOCUS['DrawHeader']);

			if($_REQUEST['mailing_labels']=='Y')
			{
				echo '<BR><BR><BR>';
				DrawHeader(Config('TITLE').' '._('Letter'));
				DrawHeader($student['FULL_NAME'],$student['STUDENT_ID']);
				DrawHeader($student['GRADE_ID'],GetSchool(UserSchool()));
				DrawHeader($course_title,GetMP(GetCurrentMP('QTR',DBDate())));
				DrawHeader(ProperDate(DBDate()));

				echo '<BR><BR><TABLE width=100%><TR><TD width=50> &nbsp; </TD><TD>'.$student['MAILING_LABEL'].'</TD></TR></TABLE><BR>';
			}
			else
				DrawHeader(Config('TITLE').' '._('Letter'));

			$letter_text = $_REQUEST['letter_text'];
			foreach($student as $column=>$value)
				$letter_text = str_replace('__'.$column.'__',$value,$letter_text);
			echo '<TABLE width=100%><TR><TD>'.$letter_text.'</TD></TR></TABLE>';
			echo '<!-- NEW PAGE -->';
		}
		PDFStop($handle);
	}
	else
		BackPrompt(_('No Students were found.'));
}
?>